﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Windows.ApplicationModel.Core;
using Windows.UI;
using Windows.UI.Core;
using Windows.UI.Text;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using com.IronOne.BoardPACWinApp.Common;
using com.IronOne.BoardPACWinApp.Helpers;
using com.IronOne.BoardPACWinAppBO.Category;
using com.IronOne.BoardPACWinAppBO.General;
using com.IronOne.BoardPACWinAppBO.Meeting;
using com.IronOne.BoardPACWinAppBO.Sync;
using com.IronOne.BoardPACWinAppService.Agenda;
using com.IronOne.BoardPACWinAppService.Auth;
using com.IronOne.BoardPACWinAppService.Category;
using com.IronOne.BoardPACWinAppService.Meeting;
using com.IronOne.BoardPACWinAppUtil.Enums;
using com.IronOne.BoardPACWinAppUtil.Util;
using GalaSoft.MvvmLight.Messaging;
using com.IronOne.BoardPACWinApp.View.UserControl;
using com.IronOne.BoardPACWinAppBO.Paper;

// The Basic Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234237

namespace com.IronOne.BoardPACWinApp.View.Page
{
    /// <summary>
    ///     A basic page that provides characteristics common to most applications.
    /// </summary>
    public sealed partial class MeetingsPage
    {
        public static bool IsOneTime = true;
        public static CategoryModel GlobalCategorySelectedItem = new CategoryModel();
        public static SubCategoryModel GlobalSubCategorySelectedItem = new SubCategoryModel();
        private IAgendaService _agendaService;
        private ICategoryService _categoryService;
        private int _globalCategoryId = -1;
        private List<CategoryModel> _globalCategoryList;
        private List<MeetingModel> _globalMeetings;
        private int _globalSubCategoryId = -1;
        private List<SubCategoryModel> _globalSubCategoryList;
        private IMeetingService _meetingService;
        private INavigationService _navigationService;
        private readonly IDialogService _dialogService;
        private NewsAndSharedDocModel _newsAndSharedDocs = new NewsAndSharedDocModel();
        //This need on the sync response
        private int _selectedMeetingStatus = -1;
        private readonly IAuthService _authService;

        public MeetingsPage()
        {
            InitializeComponent();
            NavigationHelper = new NavigationHelper(this);

            _navigationService = new NavigationService();
            _categoryService = new CategoryService();
            _meetingService = new MeetingService();
            _agendaService = new AgendaService();
            _authService = new AuthService();
            _dialogService = new DialogService();
        }

        /// <summary>
        ///     NavigationHelper is used on each page to aid in navigation and
        ///     process lifetime management
        /// </summary>
        public NavigationHelper NavigationHelper { get; private set; }

        protected override async void HandleMessages(NotificationMessage<MessageDataModel> mdm)
        {
            try
            {
                base.HandleMessages(mdm);
                await BasePage.GetInstance().HandleMessages(mdm);

                if (!mdm.Notification.Equals(MessageCodes.SYNC_UPDATED_DATA)) return;

                var sudm = (SyncUpdatedDataModel)mdm.Content.MessageData;
                if (sudm.Meetings != null && sudm.Meetings.Count > 0)
                {
                    await QueryMeetings(sudm.Meetings);
                }

                if ((sudm.AgendaItemIds != null && sudm.AgendaItemIds.Count > 0) || sudm.IsUpdatedOrDeletedAgendaItems ||
                    sudm.IsUpdatedOrDeletedHeadingItems)
                {
                    if (_globalMeetings != null && _globalMeetings.Count > 0)
                        await QueryMeetings(_globalMeetings);
                }

                //if ((sudm.Comments != null && sudm.Comments.Count > 0) || (sudm.IsNewOrUpdatedNewsOrSharedItems))
                if ((sudm.Comments != null && sudm.Comments.Count > 0) ||
                    (sudm.AgendaItemIds != null && sudm.AgendaItemIds.Count > 0) || (sudm.IsUpdatedOrDeletedAgendaItems) ||
                    (sudm.IsNewOrUpdatedNewsOrSharedItems))
                {
                    await NewsAndShardItemsDisplay();

                    //NOTE: This will update meeting's meeting comments count
                    if (sudm.Comments != null && sudm.Comments.Count > 0 && _globalMeetings != null &&
                        _globalMeetings.Count > 0)
                    {
                        // 1 means Meeting Comment
                        var rslt = sudm.Comments.Select(k => k.Value == "1").ToList();
                        if (rslt == null) return;
                        await QueryMeetings(_globalMeetings);
                    }
                }

                if (sudm.IsNewOrUpdatedCategories)
                {
                    await PopulateCategoryListView();
                    return;
                }

                if (!sudm.IsNewOrUpdatedSubCategories) return;

                #region GetSubCategoriesByCategoryId

                var lhdm =
                    await
                        CommonHelper.GetInstance()
                            .RefereshSubCategoryListView(_categoryService, _globalCategoryId, _globalSubCategoryList,
                                SubCategoryListView, GlobalSubCategorySelectedItem);
                _globalSubCategoryList = lhdm.GlobalSubCategoryList;

                #endregion
            }
            catch (Exception)
            {
            }
        }

        /// <summary>
        ///     Populates the page with content passed during navigation.  Any saved state is also
        ///     provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">
        ///     The parameter value passed to
        ///     <see cref="Frame.Navigate(Type, Object)" /> when this page was initially requested.
        /// </param>
        /// <param name="pageState">
        ///     A dictionary of state preserved by this page during an earlier
        ///     session.  This will be null the first time a page is visited.
        /// </param>
        protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {
        }

        /// <summary>
        ///     Preserves state associated with this page in case the application is suspended or the
        ///     page is discarded from the navigation cache.  Values must conform to the serialization
        ///     requirements of <see cref="SuspensionManager.SessionState" />.
        /// </summary>
        /// <param name="pageState">An empty dictionary to be populated with serializable state.</param>
        protected override void SaveState(Dictionary<String, Object> pageState)
        {
        }

        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            try
            {
                base.OnNavigatedTo(e);
                NavigationHelper.OnNavigatedTo(e);

                #region SettingBars && Settings checkup

                var isPinned = new AppSettingsManager().GetAppBarPinnedStatus();

                if (IsOneTime)
                {
                    IsOneTime = false;
                    CloseAppBars(isPinned);

                    //NOTE: All the other checkups due on startup of the app
                    #region Failure of this should not cause any issue to main code

                    #region Check and initiate date format
                    try
                    {
                        await CheckAndInitiateDateFormat();
                    }
                    catch (Exception)
                    {
                    } 
                    #endregion

                    #region Annotation automatic backup
                    try
                    {
                        /// <summary>
                        /// [0] - IsBackupOnOff
                        /// [1] - Backup duration in days
                        /// [2] - Formatted datetime of last backup
                        /// [3] - Formatted datetime of next backup
                        var data = await _agendaService.GetAnnotationBackupDates();
                        if (data[0].Equals("1"))
                        {
                            int duration = Convert.ToInt32(data[1]);
                            var lastbackup = Convert.ToDateTime(data[2]);
                            if ((DateTime.Now.Subtract(lastbackup)).TotalDays >= duration)
                            {
                                await Task.Run(() => _agendaService.InitiateBackgroundAnnotBackup());
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                    #endregion

                    #region App offline usage reset if online
                    if (Global.IsOnline && !Global.UserForceWentOffline)
                    {
                        try
                        {
                            //NOTE: Update today date if online so 'EnforceOnlineLoginDuration' condition will not reach
                            await _authService.SetSettingUsageValueBySettingName(ApplicationConstants.UserDbSettingNames.EnforceOnlineLoginDuration, DateTime.Now.ToString());
                            //NOTE: Reset the usage counter because user login online mode
                            await _authService.SetSettingUsageValueBySettingName(ApplicationConstants.UserDbSettingNames.OfflineConsecutiveLimit, "0");
                        }
                        catch (Exception)
                        {
                        }
                    }
                    #endregion

                    #region Check for pending approvals
                    try
                    {
                        await CheckAndNotifyPendingApprovals();
                    }
                    catch (Exception)
                    {
                    }
                    #endregion

                    #endregion
                }
                else
                {
                    PageTopAppBar.IsOpen = false;
                    if (!isPinned)
                        PageBottomAppBar.IsOpen = false;
                }

                #endregion

                await PopulateCategoryListView();
                //await PopulateMeetingGridView();

                //TODO: read datetime from server and put here
                DayTextBlock.Text = DateTime.Now.Day.ToString();
                MonthTextBlock.Text = " " + DateTime.Now.ToString("MMM");
                YearTextBlock.Text = " " + DateTime.Now.Year;

                MenuItem1TextBlock.Foreground = new SolidColorBrush(Colors.Black);

                await NewsAndShardItemsDisplay();

                AgendaPage.OrgAgendaModel = null;
                AgendaPage.GlobalSelectdAgendaItem = null;

                CalenderPage.GlobalCategorySelectedItem = null;
                CalenderPage.GlobalSubCategorySelectedItem = null;
                CalenderPage.GlobalSelectedCalender = -1;
                GeneralSettingsFlyout.IsFirstTime = false;


            }
            catch (Exception)
            {
            }
            finally
            {
                PgbPage.Visibility = Visibility.Collapsed;
            }
        }

        private async Task CheckAndNotifyPendingApprovals()
        {
            try
            {
                var isShow = await _authService.GetSettingValueBySettingName(DatabaseType.UserDb, ApplicationConstants.UserDbSettingNames.ShowPendingApprovalAlert);
                if (isShow != null && isShow.ToString().Equals("1"))
                {
                    var noOfDays = await _authService.GetSettingValueBySettingName(DatabaseType.UserDb, ApplicationConstants.UserDbSettingNames.CheckedNoOfDaysPendingApprovals);
                    if (noOfDays == null) return;
                    int days = Convert.ToInt32(noOfDays);
                    int approvalCount = await _agendaService.GetPendingApprovalsPapersList(days);

                    if (approvalCount <= 0) return;

                    string daysStr = (days > 1) ? "days" : "day";
                    string approvalStr = (approvalCount > 1) ? "approvals" : "approval";
                    _dialogService.ShowMessage("You have " + approvalCount + " " + approvalStr + " pending over " + days + " " + daysStr + ".\nPlease attend.");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// This func will reinitialize the date format due to user chose "Server decide" before login
        /// and can't use userdb value coz we don't know the user.
        /// Can't remove "Server decide" before login from general settings coz if user already selected that
        /// option we need to display it regardless of user's login status
        /// </summary>
        /// <returns></returns>
        private async Task CheckAndInitiateDateFormat()
        {
            try
            {
                Global.DateFormat = await _authService.CheckAndInitiateDateFormat();
            }
            catch (Exception)
            {
                throw;
            }
        }

        private async Task NewsAndShardItemsDisplay()
        {
            try
            {
                //News and shared doc Items
                _newsAndSharedDocs = await _agendaService.GetNewsAndSharedDocsList();

                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    if (_newsAndSharedDocs.NewsItems != null && _newsAndSharedDocs.NewsItems.Count > 0)
                    {
                        FirstNewsItemNameTextBlock.Text = _newsAndSharedDocs.NewsItems[0].DocName;
                        FirstNewsItemDateTextBlock.Text = _newsAndSharedDocs.NewsItems[0].LastUpadatedDateTimeDisplay;
                        NewsItemsCountTextBlock.Text = (_newsAndSharedDocs.NewsItems.Count >
                                                        Utility.GetMaxCountDisplay())
                            ? Utility.GetMaxCountDisplayOnUi()
                            : _newsAndSharedDocs.NewsItems.Count.ToString();
                    }

                    if (_newsAndSharedDocs.SharedDocs != null && _newsAndSharedDocs.SharedDocs.Count > 0)
                    {
                        FirstSharedDocNameTextBlock.Text = _newsAndSharedDocs.SharedDocs[0].DocName;
                        FirstSharedDocDateTextBlock.Text = _newsAndSharedDocs.SharedDocs[0].LastUpadatedDateTimeDisplay;
                        SharedDocsCountTextBlock.Text = (_newsAndSharedDocs.SharedDocs.Count >
                                                         Utility.GetMaxCountDisplay())
                            ? Utility.GetMaxCountDisplayOnUi()
                            : _newsAndSharedDocs.SharedDocs.Count.ToString();
                    }

                    NewPapersCountTextBlock.Text = (_newsAndSharedDocs.NewPapers > Utility.GetMaxCountDisplay())
                        ? Utility.GetMaxCountDisplayOnUi()
                        : _newsAndSharedDocs.NewPapers.ToString();
                    NewCommentsCountTextBlock.Text = (_newsAndSharedDocs.NewComments > Utility.GetMaxCountDisplay())
                        ? Utility.GetMaxCountDisplayOnUi()
                        : _newsAndSharedDocs.NewComments.ToString();
                });
            }
            catch (Exception)
            {
            }
        }

        private async void CloseAppBars(bool isPinned)
        {
            try
            {
                PageTopAppBar.IsOpen = true;
                PageBottomAppBar.IsOpen = true;

                if (await WaitAsync())
                {
                    PageTopAppBar.IsOpen = false;
                    if (!isPinned)
                        PageBottomAppBar.IsOpen = false;
                }
            }
            catch (Exception)
            {
            }
        }

        public async Task<bool> WaitAsync()
        {
            await Task.Delay(1000);
            return true;
        }

        private async Task PopulateCategoryListView()
        {
            var helper =
                await
                    CommonHelper.GetInstance()
                        .PopulateCategoryListView(_globalCategoryList, _categoryService, GlobalCategorySelectedItem,
                            CategoryListView, _globalSubCategoryId, GlobalSubCategorySelectedItem);
            _globalCategoryList = helper.GlobalCategoryList;
            GlobalCategorySelectedItem = helper.GlobalCategorySelectedItem;
            _globalSubCategoryId = helper.GlobalSubCategoryId;
            GlobalSubCategorySelectedItem = helper.GlobalSubCategorySelectedItem;
        }

        private void SubMenuManip()
        {
            MenuItem1TextBlock.Foreground = new SolidColorBrush(Colors.Gray);
            MenuItem2TextBlock.Foreground = new SolidColorBrush(Colors.Gray);
            MenuItem3TextBlock.Foreground = new SolidColorBrush(Colors.Gray);
            MenuItem4TextBlock.Foreground = new SolidColorBrush(Colors.Gray);
            MenuItem1TextBlock.FontWeight = FontWeights.Light;
            MenuItem2TextBlock.FontWeight = FontWeights.Light;
            MenuItem3TextBlock.FontWeight = FontWeights.Light;
            MenuItem4TextBlock.FontWeight = FontWeights.Light;
        }

        private async void CategoryListViewSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                #region CommonCategoryListViewSelectionChanged

                var lhdm =
                    await
                        CommonHelper.GetInstance()
                            .CommonCategoryListViewSelectionChanged(CategoryListView, _categoryService,
                                SubCategoryListView, GlobalSubCategorySelectedItem);
                if (lhdm != null)
                {
                    GlobalCategorySelectedItem = lhdm.GlobalCategorySelectedItem;
                    _globalCategoryId = lhdm.GlobalCategoryId;
                    _globalSubCategoryList = lhdm.GlobalSubCategoryList;
                    GlobalSubCategorySelectedItem = lhdm.GlobalSubCategorySelectedItem;
                }

                #endregion

                await GetMeetings();
            }
            catch (Exception)
            {
            }
        }

        private async void SubCategoryListViewSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                #region SubCategoryListViewSelectionChanged

                var lhdm = CommonHelper.GetInstance().CommonSubCategoryListViewSelectionChanged(SubCategoryListView);
                _globalSubCategoryId = lhdm.GlobalSubCategoryId;
                GlobalSubCategorySelectedItem = lhdm.GlobalSubCategorySelectedItem;

                #endregion

                await GetMeetings();
            }
            catch (Exception)
            {
            }
        }

        private async void MeetingGridViewSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                await
                    CommonHelper.GetInstance()
                        .CommonMeetingGridViewSelectionChanged(MeetingGridView, _categoryService,
                            _navigationService, _globalCategoryList, _globalSubCategoryList, _globalCategoryId,
                            _globalSubCategoryId);
            }
            catch (Exception)
            {
            }
        }

        private async Task GetMeetings()
        {
            try
            {
                var meetings = await _meetingService.GetMeetings(_globalCategoryId, _globalSubCategoryId);
                if (meetings == null || meetings.Count <= 0)
                {
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        MeetingGridView.DataContext = null;
                        _globalMeetings = null;
                    });
                    return;
                }

                _globalMeetings = await CommonHelper.GetInstance().CommonListViewUiManipulations(_authService, meetings);

                if (_selectedMeetingStatus != (int)MeetingStatus.All)
                    meetings = meetings.Where(x => x.MeetingStatus == (byte)_selectedMeetingStatus).ToList();

                await
                    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                        () => { MeetingGridView.DataContext = meetings; });
            }
            catch (Exception)
            {
            }
        }

        private async Task QueryMeetings(List<MeetingModel> meetings)
        {
            try
            {
                List<MeetingModel> qMeetings;

                if (_selectedMeetingStatus != -1) //SelectedMeetingStatus
                {
                    qMeetings = meetings.Where(x => x.MeetingStatus == (byte)_selectedMeetingStatus).ToList();
                    if (qMeetings == null || qMeetings.Count < 1)
                        return;
                }
                else
                    qMeetings = meetings;

                if (_globalCategoryId != -1 && _globalSubCategoryId == -1)
                //category selected | subcategory not selected
                {
                    qMeetings = qMeetings.Where(x => x.CategoryId == _globalCategoryId).ToList();
                    if (qMeetings != null && qMeetings.Count > 0)
                        await GetMeetings();
                    return;
                }

                if (_globalCategoryId != -1 && _globalSubCategoryId != -1) //category and subcategory both selected
                {
                    qMeetings =
                        qMeetings.Where(
                            x => x.CategoryId == _globalCategoryId && x.SubCategoryId == _globalSubCategoryId).ToList();
                    if (qMeetings != null && qMeetings.Count > 0)
                        await GetMeetings();
                    return;
                }

                if (_globalCategoryId == -1 && _globalSubCategoryId == -1) //All
                {
                    await GetMeetings();
                }
            }
            catch (Exception)
            {
            }
        }

        private void CalenderUserControl_Tapped(object sender, TappedRoutedEventArgs e)
        {
            _navigationService.NavigateTo(typeof(CalenderPage));
        }

        private void NewsGrid_Tapped(object sender, TappedRoutedEventArgs e)
        {
            if (_newsAndSharedDocs.NewsItems != null && _newsAndSharedDocs.NewsItems.Count > 0)
                _navigationService.NavigateTo(typeof(NewsAndShardDocsPage), _newsAndSharedDocs.NewsItems);
        }

        private void ShardDocsGrid_Tapped(object sender, TappedRoutedEventArgs e)
        {
            if (_newsAndSharedDocs.SharedDocs != null && _newsAndSharedDocs.SharedDocs.Count > 0)
                _navigationService.NavigateTo(typeof(NewsAndShardDocsPage), _newsAndSharedDocs.SharedDocs);
        }

        private void NewCommentsPanel_Tapped(object sender, TappedRoutedEventArgs e)
        {
            if (_newsAndSharedDocs.NewComments > 0)
                _navigationService.NavigateTo(typeof(CommentsPage));
        }

        private void pageRoot_Unloaded(object sender, RoutedEventArgs e)
        {
            _navigationService = null;
            _categoryService = null;
            _meetingService = null;
            _agendaService = null;
        }

        /*private async Task PopulateCategoryListView()
        {
            try
            {
                GlobalCategoryList = await _categoryService.GetCategories();
                if (GlobalCategoryList != null && GlobalCategoryList.Count > 0)
                {
                    GlobalCategoryList.Insert(0, new CategoryModel() { CategoryID = -1, CategoryName = "All", ShortName = "All" });
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        // Your UI update code goes here!
                        CategoryModel cmo = null;
                        if (GlobalCategorySelectedItem != null)
                        {
                            cmo = new CategoryModel();
                            cmo.Actions = GlobalCategorySelectedItem.Actions;
                            cmo.CategoryID = GlobalCategorySelectedItem.CategoryID;
                            cmo.CategoryName = GlobalCategorySelectedItem.CategoryName;
                            cmo.CategoryOrder = GlobalCategorySelectedItem.CategoryOrder;
                            cmo.Info = GlobalCategorySelectedItem.Info;
                            cmo.LastUpdatedDateTime = GlobalCategorySelectedItem.LastUpdatedDateTime;
                            cmo.ShortName = GlobalCategorySelectedItem.ShortName; 
                        }

                        CategoryListView.DataContext = GlobalCategoryList;
                        if (cmo == null) CategoryListView.SelectedIndex = 0;
                        else
                        {
                            try { CategoryListView.SelectedIndex = GlobalCategoryList.FindIndex(x => x.CategoryID == cmo.CategoryID); }
                            catch (Exception)
                            {
                                //If selectd category above is deleted from backend then first item will be selected 
                                CategoryListView.SelectedIndex = 0;
                                GlobalSubCategoryId = -1;
                                GlobalSubCategorySelectedItem = null;
                            }
                        }

                        if (CategoryListView.SelectedIndex == -1)
                        {
                            CategoryListView.SelectedIndex = 0;
                        }
                    });
                }
            }
            catch (Exception)
            {
            }
        }*/

        /*private void PopulateSubCategoryListView()
        {
            //SubCategoryListView.DataContext = await _categoryService.GetAllSubCategories();
            //CategoryListView.SelectedIndex = 0;
        }*/

        /*private async Task PopulateMeetingGridView()
        {
            await GetMeetings();
        }*/

        #region Sub Menu

        //ALL
        private void MenuItem1TextBlock_Tapped(object sender, TappedRoutedEventArgs e)
        {
            SubMenuManip();
            MenuItem1TextBlock.Foreground = new SolidColorBrush(Colors.Black);
            MenuItem1TextBlock.FontWeight = FontWeights.SemiBold;
            _selectedMeetingStatus = (int)MeetingStatus.All;
            MeetingGridView.DataContext = _globalMeetings;
        }

        //NEXT
        private void MenuItem2TextBlock_Tapped(object sender, TappedRoutedEventArgs e)
        {
            SubMenuManip();
            MenuItem2TextBlock.Foreground = new SolidColorBrush(Colors.Black);
            MenuItem2TextBlock.FontWeight = FontWeights.SemiBold;
            _selectedMeetingStatus = (int)MeetingStatus.Next;
            MeetingGridView.DataContext = _globalMeetings == null ? null : _globalMeetings.Where(x => x.MeetingStatus == (byte)MeetingStatus.Next).ToList();
        }

        //SCHEDULED
        private void MenuItem3TextBlock_Tapped(object sender, TappedRoutedEventArgs e)
        {
            SubMenuManip();
            MenuItem3TextBlock.Foreground = new SolidColorBrush(Colors.Black);
            MenuItem3TextBlock.FontWeight = FontWeights.SemiBold;
            _selectedMeetingStatus = (int)MeetingStatus.Schedule;
            MeetingGridView.DataContext = _globalMeetings == null ? null : _globalMeetings.Where(x => x.MeetingStatus == (byte)MeetingStatus.Schedule).ToList();
        }

        //LAST
        private void MenuItem4TextBlock_Tapped(object sender, TappedRoutedEventArgs e)
        {
            SubMenuManip();
            MenuItem4TextBlock.Foreground = new SolidColorBrush(Colors.Black);
            MenuItem4TextBlock.FontWeight = FontWeights.SemiBold;
            _selectedMeetingStatus = (int)MeetingStatus.Last;
            MeetingGridView.DataContext = _globalMeetings == null ? null : _globalMeetings.Where(x => x.MeetingStatus == (byte)MeetingStatus.Last).ToList();
        }

        #endregion

        private void Page_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            if (e.NewSize.Width <= Utility.GetNarrowWidthSize())
            {
                CalenderGrid.Visibility = Visibility.Collapsed;
            }
            else
            {
                CalenderGrid.Visibility = Visibility.Visible;
                switch (ApplicationView.GetForCurrentView().Orientation)
                {
                    // landscape
                    case ApplicationViewOrientation.Landscape:
                        Grid.SetRow(CalenderGrid, 10);
                        Grid.SetRowSpan(CalenderGrid, 6);
                        CalenderUserControl.Visibility = Visibility.Visible;
                        CalImage.Visibility = Visibility.Collapsed;
                        break;

                    // portrait
                    case ApplicationViewOrientation.Portrait:
                        Grid.SetRow(CalenderGrid, 10);
                        Grid.SetRowSpan(CalenderGrid, 6);
                        CalenderUserControl.Visibility = Visibility.Collapsed;
                        CalImage.Visibility = Visibility.Visible;
                        break;
                }
            }
        }

        //private void AppbarOpener_Tapped(object sender, TappedRoutedEventArgs e)
        //{
        //    if (TopAppBar != null) TopAppBar.IsOpen = true;
        //    if (BottomAppBar != null) BottomAppBar.IsOpen = true;
        //}
    }
}